import type { FormSchemaGetter } from '#/adapter/form';
import type { VxeGridProps } from '#/adapter/vxe-table';

import { DictEnum } from '@vben/constants';

import { getDictOptions } from '#/utils/dict';
import { renderDict } from '#/utils/render';

export const querySchema: FormSchemaGetter = () => [
  {
    component: 'Input',
    fieldName: 'name',
    label: '展会名称',
  },
  {
    component: 'Select',
    fieldName: 'number',
    componentProps: {
      options: getDictOptions(DictEnum.EXHIBITION_NUMBER, true),
    },
    label: '届数',
  },
  {
    component: 'Select',
    fieldName: 'year',
    componentProps: {
      options: getDictOptions(DictEnum.EXHIBITION_YEAR, true),
    },
    label: '年份',
  },
  {
    component: 'Select',
    fieldName: 'isDefault',
    componentProps: {
      options: getDictOptions(DictEnum.BUSINESS_YES_NO, true),
    },
    label: '是否默认',
  },
  {
    component: 'Select',
    fieldName: 'status',
    componentProps: {
      options: getDictOptions(DictEnum.SYS_NORMAL_DISABLE),
    },
    label: '状态',
  },
];

export const columns: VxeGridProps['columns'] = [
  {
    field: 'name',
    title: '展会名称',
  },
  {
    field: 'number',
    title: '届数',
    width: 100,
    slots: {
      default: ({ row }) => {
        return renderDict(row.number, DictEnum.EXHIBITION_NUMBER, true);
      },
    },
  },
  {
    field: 'year',
    title: '年份',
    width: 120,
    slots: {
      default: ({ row }) => {
        return renderDict(row.year, DictEnum.EXHIBITION_YEAR, true);
      },
    },
  },
  {
    field: 'isDefault',
    title: '是否默认',
    slots: { default: 'isDefault' },
  },
  {
    field: 'status',
    title: '状态',
    slots: { default: 'status' },
  },
  {
    field: 'remark',
    title: '备注',
    showOverflow: true,
  },
  {
    field: 'createTime',
    title: '创建时间',
    width: 180,
  },
  {
    field: 'action',
    fixed: 'right',
    slots: { default: 'action' },
    title: '操作',
    resizable: false,
    width: 'auto',
  },
];

export const drawerSchema: FormSchemaGetter = () => [
  {
    label: 'ID',
    fieldName: 'id',
    component: 'Input',
    dependencies: {
      show: () => false,
      triggerFields: [''],
    },
  },
  {
    component: 'Input',
    fieldName: 'name',
    label: '展会名称',
    rules: 'required',
  },
  {
    component: 'Select',
    fieldName: 'number',
    label: '届数',
    componentProps: {
      options: getDictOptions(DictEnum.EXHIBITION_NUMBER, true),
    },
    rules: 'selectRequired',
  },
  {
    component: 'Select',
    fieldName: 'year',
    label: '年份',
    componentProps: {
      options: getDictOptions(DictEnum.EXHIBITION_YEAR, true),
    },
    rules: 'selectRequired',
  },
  {
    label: '是否默认',
    fieldName: 'isDefault',
    component: 'RadioGroup',
    componentProps: {
      buttonStyle: 'solid',
      options: getDictOptions(DictEnum.BUSINESS_YES_NO, true),
      optionType: 'button',
    },
    defaultValue: 0,
    help: '设为默认后，相关数据将默认关联此展会数据，比如观众预登记后自动关联默认展会。',
    rules: 'selectRequired',
  },
  {
    label: '状态',
    fieldName: 'status',
    component: 'RadioGroup',
    componentProps: {
      buttonStyle: 'solid',
      options: getDictOptions(DictEnum.SYS_NORMAL_DISABLE),
      optionType: 'button',
    },
    defaultValue: '0',
    rules: 'selectRequired',
  },
  {
    component: 'Textarea',
    fieldName: 'remark',
    label: '备注',
  },
];
